<template>
  <div class="button-setting">
    <el-tabs v-model="active">
      <el-tab-pane label="组件属性" name="first">
        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">按钮样式</div>
          </el-col>
          <el-col :span="18">
            <el-select
              @change="btnTypeCh($event, store.current)"
              v-model="store.current.options.defaultValue"
              placeholder="请选择"
            >
              <el-option
                v-for="i1 in parameter.type"
                :key="i1.value"
                :label="i1.label"
                :value="i1.value"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">按钮名</div>
          </el-col>
          <el-col :span="18">
            <el-input
              v-model="store.current.options.name"
              placeholder="请输入按钮名"
            ></el-input>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <div class="prop-set-title">
              <h5>元素偏移</h5>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">X位移</div>
          </el-col>
          <el-col :span="18">
            <el-slider v-model="store.current.options.transform.x"></el-slider>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">Y位移</div>
          </el-col>
          <el-col :span="18">
            <el-slider v-model="store.current.options.transform.y"></el-slider>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">提交主键</div>
          </el-col>
          <el-col :span="18">
            <el-switch
              v-model="store.current.options.isSubmit"
              active-color="#13ce66"
              inactive-color="#ff4949"
            >
            </el-switch>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">是否确认</div>
          </el-col>
          <el-col :span="18">
            <el-switch
              v-model="store.current.options.isConfirm"
              active-color="#13ce66"
              inactive-color="#ff4949"
            >
            </el-switch>
          </el-col>
        </el-row>

        <div
          class="confirm-wrap"
          v-if="
            store.current.options.isConfirm &&
            store.current.options.confirmOption
          "
        >
          <el-card>
            <div slot="header" class="clearfix">
              <span>确认框配置</span>
            </div>
            <el-row>
              <el-col :span="6">
                <div class="prop-set-title">标题</div>
              </el-col>
              <el-col :span="18">
                <el-input
                  v-model="store.current.options.confirmOption.title"
                  placeholder="请输入确认框标题"
                ></el-input>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <div class="prop-set-title">类型</div>
              </el-col>
              <el-col :span="18">
              <el-select v-model="store.current.options.confirmOption.type" placeholder="请选择">
                <el-option
                  v-for="item in confirmOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <div class="prop-set-title">描述</div>
              </el-col>
              <el-col :span="18">
                <el-input
                type="textarea"
                 autosize
                  v-model="store.current.options.confirmOption.content"
                  placeholder="请输入确认框描述"
                ></el-input>
              </el-col>
            </el-row>
          </el-card>
        </div>

        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">触发条件</div>
          </el-col>
          <el-col :span="18">
            <el-select
              v-model="store.current.options.triggerType"
              placeholder="请选择触发类型"
            >
              <el-option
                v-for="trigger in triggerTypes"
                :key="trigger.value"
                :label="trigger.label"
                :value="trigger.value"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">事件名称</div>
          </el-col>
          <el-col :span="18">
            <el-select
              v-model="store.current.options.eventCode"
              clearable
              placeholder="请选择事件名称"
            >
              <el-option
                v-for="trigger in store.eventCollection"
                :key="trigger.value"
                :label="trigger.label"
                :value="trigger.value"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <div class="prop-set-title">关联弹框</div>
          </el-col>
          <el-col :span="18">
            <el-select
              v-model="store.current.options.dialogKey"
              clearable
              placeholder="请选择触发类型"
            >
              <el-option
                v-for="dialog in allDialogs"
                :key="dialog.value"
                :label="dialog.label"
                :value="dialog.value"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { triggerType } from "@/low-code/utils/enumeration.js";
import clone from "clone";
export default {
  inject: ["getStore"],
  data() {
    return {
      active: "first",
      confirmOptions:[
        {
            label: "成功",
            value: "success",
        },
        {
            label: "提示",
            value: "info",
        },
        {
            label: "警告",
            value: "warning",
        },
        {
            label: "错误",
            value: "error",
        },
      ],
      parameter: {
        // "primary", "success", "info", "warning", "danger"
        type: [
          {
            label: "primary",
            value: "primary",
          },
          {
            label: "success",
            value: "success",
          },
          {
            label: "info",
            value: "info",
          },
          {
            label: "warning",
            value: "warning",
          },
          {
            label: "danger",
            value: "danger",
          },
        ],
      },
      triggerTypes: [
        {
          label: "单击",
          value: triggerType.CLICK,
        },
        {
          label: "双击",
          value: triggerType.DOUBLECLICK,
        },
      ],
    };
  },
  methods: {
    btnTypeCh(e, current) {
      console.log(e);
      current.options.type = e;
    },
  },
  watch: {
    "store.current.options": {
      handler() {
        //特别注意，不能用箭头函数，箭头函数，this指向全局
        this.$handleStack.push(clone(this.store.root));
      },
      // immediate: true,  //刷新加载 立马触发一次handler
      deep: true, // 可以深度检测到 obj 对象的属性值的变化
    },
  },
  computed: {
    allDialogs() {
      let options = [];
      if (this.store.root.blackList && this.store.root.blackList.length > 0) {
        this.store.root.blackList.map((item) => {
          if (item.type == "sdialog") {
            options.push({
              label: item.options.name,
              value: item.key,
            });
          }
        });
      }
      return options;
    },
    store() {
      return this.getStore();
    },
  },
};
</script>

<style scoped>
.button-setting >>> #tab-first {
  width: 100%;
  color: #303133;
  text-align: center;
}
.confirm-wrap {
  padding: 5px 10px;
}
</style>

